//$(function() {
//	document.addEventListener('touchmove', function(e) {
//		e.preventDefault();
//	}, false);
//})
var search = {
	init: function() {
		var self = this;
		var obj = $(".wd");
		var btn = $(".jk-btn");
		var swrap = $(".jk-search");
		var del = $(".jk-search-del-icon");
		self.change(obj, btn, del);
		self.event(swrap);
	},
	change: function(chg, btc, cut) {
		chg.focus(function() {
			$(".headnav").slideUp("fast");
			btc.show(100, function() {
				$(this).parents(".jk-search").addClass("change");
			})
			$(this).keyup(function() {
				var keystr = $.trim($(this).val());
				if (keystr != "") {
					cut.show(0, function() {
						$(".search_pro").show();
						btc.removeClass("cancel").addClass("search").text("搜索");
					});
				} else {
					cut.hide(0, function() {
						$(".search_pro").hide();
						btc.removeClass("search").addClass("cancel").text("取消");
					});
				}
			})
		})
		cut.click(function() {
			$(this).hide(0, function() {
				$(".search_pro").hide();
				btc.removeClass("search").addClass("cancel").text("取消");
				chg.val("");
			})
		});
	},
	event: function(btn) {
		btn.on("click", ".search", function() {
			SearchSubmit($("#wd").val(), event)
		})
		btn.on("click", ".cancel", function() {
			$(".headnav").slideDown("fast");
			$(this).hide(0, function() {
				$(this).parents(".jk-search").removeClass("change");
			})
		})
	}
}
search.init();


var cly = {
	init: function() { //init this function 
		var self = this;
		var rightobj = $(".right-cly-con");
		var list = $(".list");
		var main = $(".jk-cly-list");
		var winH = $(window).height();
		var topH = $(".header-top").height();
		var searchH = $(".jk-search").height();
		var listH = $(".jk-m-list");
		var topmenu = $(".menu-open-button");
		main.height(winH - (topH + searchH));
		self.leftcly(list, topmenu);
		self.defaultImg();
	},
	defaultImg: function() { //list default images
		var def = $(".cly-con>li").eq(0).find("img");
		var defAdd = def.attr("original");
		$.each(def, function(i) {
			var add = def.eq(i).attr("original");
			def.eq(i).attr("src", function() {
				return add
			}).fadeIn(200);
			rightlist.refresh();

		})
	},
	leftcly: function(obj, menu) { //click show images
		var leftlist = new IScroll('.left-cly', {
			mouseWheel: true,
			click: true
		});
		rightlist = new IScroll('.right-cly-con', {
			mouseWheel: true,
			click: true,
			momentum: false
		});
		menu.click(function() {
			var navtoggle = $(".jk-sub-nav");
			var s = navtoggle.css("height");
			var main_list = $(".jk-cly-list");
			navtoggle.toggle();
			if (navtoggle.is(":visible")) {
				main_list.height(main_list.height() - parseInt(s));
				leftlist.refresh();
				rightlist.refresh();
			} else {
				main_list.height(main_list.height() + parseInt(s));
				leftlist.refresh();
				rightlist.refresh();

			}
		})
		obj.on("click", "li", function() {
			var $img = $(".cly-con>li").eq($(this).index()).find("img"); //get all this index images address					
			$("input").blur();
			obj.find("li").removeClass("active");
			leftlist.scrollToElement(document.querySelector('.list li:nth-of-type(' + ($(this).index() + 1) + ')'), 1000);
			$(this).addClass("active");
			$(".cly-con>li").hide();
            $(".cly-con>li").eq($(this).index()).fadeIn("fast",function(){
            	rightlist.refresh();
            })			
			$.each($img, function(i) {
				var $src = $img.eq(i).attr("original"); //Get the current images address
				$img.eq(i).attr("src", function() {
					return $src
				}).fadeIn(200);
			})
			


		})
	},
}
cly.init();